package helpers

import scala.util.matching.Regex

trait CanonicalNamed extends Any {

  def basicName: String

  def packageName: String = this.getClass.getPackage.getName

  def canonicalName: String =
    packageName + (if (basicName.isEmpty) "" else s".$basicName")
}

trait ClassNameAsCanonicalName extends CanonicalNamed {

  protected val namePattern: Regex = """(\w+)\$""".r

  //val basicName = namePattern.findAllIn(this.getClass.getName).map(_.dropRight(1)).mkString(".")
  override def basicName: String = {
    val name = this.getClass.getSimpleName
    if (name.endsWith("$")) name.init else name
  }
}
